#ifndef QPARSER_H
#define QPARSER_H

#include <QWidget>
#include <QByteArrayMatcher>
#include <QRegExp>

enum byteDecision{BYTE_HANDLED,LIST_COMPLETE,LIST_INVALID};
//enum byteDecision{INCOMPLETE,COMPLETE,INVALID_MATCH,INVALID_BYTE};
enum vartype{BYTEARRAY,NUMBER};
enum parsingstate{START,PARSE};
enum variableProperty{VARIABLETYPE,VARFIXED,VARMATCHED,VARLENGTH,VARARRAY,VARFULL};
struct variable{            // Structure for storing variables
  vartype type;
  bool fixed;
  bool matched;
  int length;
  double floatvalue;
  QByteArray arraytomatch;
  QByteArray arrayfound;
  QString name;
};

class QParser : public QWidget
{
  Q_OBJECT

public:
  QParser(QWidget *parent = 0);

  // Variables
  QString testout;

  // Functions
  void dataparse(QByteArray);
  int varlistSize();
  bool testList();
  variable variableAt(int);
  void addVariable(variable,int);
  void remVariable(int);
  void setvarProperty(int, variableProperty,variable);
  void setType(int, vartype);
  void setMatched(int,bool);
  void setFixed(int,bool);
  void setLength(int,int);
  void setArray(int,QByteArray);
  void setName(int,QString);

signals:
  void outputList(QList<variable>,bool,QString);
  void testResult(QString,bool);

public slots:


private:
  QList<variable> varList;
  parsingstate curstate;
  QByteArray remainder;
  bool resolved;
  bool validList;
  int  vecIndex;

  // Private functions
  byteDecision CheckByte(char);
  byteDecision nextVariable(void);
  void clearVarList(void);
  bool tryNextVariable(char);
  void tryFirstVariable(char);

};

#endif // QPARSER_H
